package likou.offer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @Info:
 * @Author: Tangxz
 * @Date: 2020/09/04 17:16
 */

public class _58_2 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(maxSlidingWindow(new int[]{9,11},2)));
    }
    public static int[] maxSlidingWindow(int[] nums, int k) {
        List<Integer> temp = new ArrayList<>();
        int deep = 0;
        int[] daan = new int[nums.length-k+1];
        int index = 0;
        for(int i =0;i<nums.length;i++){
            if(deep<k-1){
                temp.add(nums[i]);
                deep++;
            }else{
                temp.add(nums[i]);
                daan[index] = temp.stream().max(new Comparator<Integer>() {
                    @Override
                    public int compare(Integer o1, Integer o2) {
                        return o1-o2;
                    }
                }).get();
                index++;
                temp.remove(0);
            }
        }
        return daan;
    }
}
